import globals from 'globals'
import pluginJs from '@eslint/js'
import tseslint from 'typescript-eslint'
import pluginVue from 'eslint-plugin-vue'
import prettierRecommended from 'eslint-plugin-prettier/recommended'
// 引入autoImport全局变量
// 1. 设置with { type: json }引入 es会宝警告 不推荐
// import autoImport from './.eslintrc-auto-import.json' with { type: json }

// 2. 推荐使用node的方式加载json
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const autoImport = require('./.eslintrc-auto-import.json')

// 3. fs.readFile

/** @type {import('eslint').Linter.C onfig[]} */
export default [
  {
    files: ['**/*.{js,mjs,cjs,ts,vue}']
  },
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...autoImport.globals
      }
    }
  },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  ...pluginVue.configs['flat/essential'],
  {
    files: ['**/*.vue'],
    languageOptions: { parserOptions: { parser: tseslint.parser } }
  },
  {
    ignores: ['node_modules', 'pnpm-lock.yaml', '**/*.{css,jpg,jpeg,png,d.ts}']
  },
  {
    rules: {
      'vue/multi-word-component-names': 'off',
      '@typescript-eslint/no-unused-vars': 'off'
    }
  },
  prettierRecommended // 覆盖掉eslint的规范
]
